package ioc

import (
	"github.com/IBM/sarama"
	"github.com/spf13/viper"
	"jk-time/webook/feed/events"
	"jk-time/webook/pkg/saramax"
)

func InitKafka() sarama.Client {
	host := viper.GetString("kafka.host")
	cfg := sarama.NewConfig()
	cfg.Producer.Return.Successes = true
	cfg.Producer.Return.Errors = true

	client, err := sarama.NewClient([]string{host}, cfg)
	if err != nil {
		panic(err)
	}
	return client
}

// NewConsumers 面临的问题依旧是所有的 Consumer 在这里注册一下
func NewConsumers(article *events.ArticleEventConsumer, feed *events.FeedEventConsumer) []saramax.Comsumer {
	return []saramax.Comsumer{
		article, feed,
	}
}
